package com.example.shiwuyouproject.ui.fragment.my.activity

import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.core.widget.addTextChangedListener
import com.example.shiwuyouproject.base.BaseVmActivity
import com.example.shiwuyouproject.databinding.ActivityTeachingcharacteristicsBinding
import com.example.shiwuyouproject.ui.fragment.my.activity.viewmodel.SuccessfulCaseViewModel
import com.example.shiwuyouproject.ui.my.bean.PersonalInformationBean
import com.yechaoa.yutilskt.ToastUtil
import com.yechaoa.yutilskt.YUtils

/**
 * 教学特点
 */
class TeachingCharacteristicsActivity:BaseVmActivity<ActivityTeachingcharacteristicsBinding, SuccessfulCaseViewModel>() {
    override fun getViewBinding(): ActivityTeachingcharacteristicsBinding {
        return  ActivityTeachingcharacteristicsBinding.inflate(layoutInflater)
    }

    override fun viewModelClass(): Class<SuccessfulCaseViewModel> = SuccessfulCaseViewModel::class.java

    override fun initView() {
        mBinding.myTitle.tvRightTitle.visibility= View.GONE
        mBinding.myTitle.tvTitle.text="教学特点"
        mViewModel.getRealNameAuthenticationData()
    }
    var stFeature=""
    override fun setListener() {
        mBinding.etContext.addTextChangedListener(object : TextWatcher {
            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }

            override fun afterTextChanged(s: Editable?) {
                mBinding.tvNumber.text = mBinding.etContext.text.length.toString()

            }
        })
        mBinding.myTitle.tvBack.setOnClickListener { finish() }
        mBinding.btSava.setOnClickListener { //保存
            YUtils.showLoading(this, "保存中...")
            stFeature=mBinding.etContext.text.toString()
            mViewModel.jiaoxuetedian(stFeature)
        }
    }


    override fun observe() {
        mViewModel.getPostStatus.observe(this,androidx.lifecycle.Observer<Boolean>{
            YUtils.hideLoading()
            if(it){
                ToastUtil.show("提交成功！")
                finish()
            }else{
                ToastUtil.show("提交失败！")
            }
        })
        mViewModel.getGenRenStatus.observe(this,androidx.lifecycle.Observer<PersonalInformationBean>{
            mBinding.etContext.setText(it.feature)
        })
    }

}